<script setup lang="ts">
import { reactive, ref } from "vue";
import { useMenu } from "@/views/nested/userAdmin/utils/hook.tsx";
import { transformI18n } from "@/plugins/i18n";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import Refresh from "@iconify-icons/ep/refresh";
import AddFill from "@iconify-icons/ri/add-circle-line";
import { useRouter } from "vue-router";
import { status } from "nprogress";
import { ElMessage } from "element-plus";
const tableDataUser = [
  {
    userName: "Tom",
    systemName: "理赔",
    status: "有效",
    createTime: "2016-05-02",
    userRemark: "理赔",
    auth: [
      {
        permissionCode: "33643",
        permissionName: "理赔",
        status: "有效",
        AuthTime: "2016-05-02"
      }
    ]
  },
  {
    userName: "Tom",
    systemName: "理赔",
    status: "有效",
    createTime: "2016-05-02",
    userRemark: "理赔",
    auth: [
      {
        permissionCode: "33643",
        permissionName: "理赔",
        status: "有效",
        AuthTime: "2016-05-02"
      }
    ]
  }
];
const tableData = [
  {
    authCode: Math.random().toString(36).substr(2, 9),
    authName: "理赔权限",
    status: "正常",
    remark: "理赔"
  }
];
const form = reactive({
  userCode: Math.random().toString(36).substr(2, 9),
  userName: "",
  system: "",
  auth: "",
  upperMenu: "",
  routerUrl: "",
  menuRemark: "",
  sort: ""
});
defineOptions({
  name: "userAdmin"
});

const formRef = ref();
const tableRef = ref();
const {
  loading,
  columns,
  openDialog,
  onSearch,
  resetForm,
  handleDelete,
  handleSelectionChange
} = useMenu();

const props = { multiple: true };
const onSubmit = () => {
  ElMessage.error("新增失败");
};
const dialogFormVisible = ref(false);
const dialogVisible = ref(false);
const router = useRouter();

const formUser = reactive({
  title: "",
  status: "",
  value1: "",
  fourthMenu: ""
});
const formData = reactive({
  userName: "Tom",
  systemName: "理赔",
  status: "有效",
  createTime: "2016-05-02",
  userRemark: "理赔"
});

const options = [
  { label: "理赔", value: "claim" },
  { label: "双核", value: "undrt" }
];

const options1 = [
  { label: "有效", value: "true" },
  { label: "无效", value: "false" }
];

const openDialogAdd = () => {
  dialogVisible.value = true;
};

const update = () => {
  dialogFormVisible.value = true;
};
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="formUser"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"
    >
      <el-form-item label="应用名称：" prop="title">
        <el-select
          v-model="formUser.title"
          placeholder="请选择应用名称"
          clearable
          class="!w-[180px]"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态：" prop="status">
        <el-select
          v-model="formUser.status"
          placeholder="请选择状态"
          clearable
          class="!w-[180px]"
        >
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间：" prop="value1">
        <el-date-picker
          v-model="formUser.value1"
          type="datetimerange"
          range-separator="To"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar
      title="角色管理"
      :columns="columns"
      :isExpandAll="false"
      :tableRef="tableRef?.getTableRef()"
      @refresh="onSearch"
    >
      <template #buttons>
        <el-button
          type="primary"
          :icon="useRenderIcon(AddFill)"
          @click="openDialogAdd()"
        >
          新增角色
        </el-button>
      </template>
      <template v-slot="{}">
        <el-table :data="tableDataUser" style="width: 100%">
          <el-table-column type="expand">
            <template #default="props">
              <div m="4">
                <el-table :data="props.row.auth">
                  <el-table-column
                    label="权限代码"
                    prop="permissionCode"
                    align="center"
                  />
                  <el-table-column
                    label="权限名称"
                    prop="permissionName"
                    align="center"
                  />
                  <el-table-column label="状态" prop="status" align="center" />
                  <el-table-column
                    label="授权时间"
                    prop="AuthTime"
                    align="center"
                  />
                </el-table>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="角色名称" prop="userName" align="center" />
          <el-table-column label="应用系统" prop="systemName" align="center" />
          <el-table-column label="状态" prop="status" align="center" />
          <el-table-column label="创建时间" prop="createTime" align="center" />
          <el-table-column label="角色描述" prop="userRemark" align="center" />
          <el-table-column
            fixed="right"
            label="操作"
            width="400px"
            align="center"
          >
            <template v-slot="{ row }">
              <el-button size="small" type="primary" @click="update()"
                >修改</el-button
              >
              <el-button size="small" type="primary">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-dialog v-model="dialogFormVisible">
          <el-form :model="formData">
            <el-form-item label="角色名称" label-width="120px">
              <el-input v-model="formData.userName" autocomplete="off" />
            </el-form-item>
            <el-form-item label="应用系统" label-width="120px">
              <el-input v-model="formData.systemName" autocomplete="off" />
            </el-form-item>
            <el-form-item label="状态" label-width="120px">
              <el-input v-model="formData.status" autocomplete="off" />
            </el-form-item>
            <el-form-item label="创建时间" label-width="120px">
              <el-input v-model="formData.createTime" autocomplete="off" />
            </el-form-item>
            <el-form-item label="角色描述" label-width="120px">
              <el-input v-model="formData.userRemark" autocomplete="off" />
            </el-form-item>
          </el-form>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取消</el-button>
              <el-button type="primary" @click="dialogFormVisible = false">
                提交
              </el-button>
            </div>
          </template>
        </el-dialog>
        <el-dialog v-model="dialogVisible">
          <el-form
            :model="form"
            label-width="auto"
            class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"
          >
            <h1 style="margin: 10px 0 20px">增加角色</h1>
            <el-form-item label="角色代码">
              <el-col :span="12">
                <el-input v-model="form.userCode" disabled />
              </el-col>
            </el-form-item>
            <el-form-item label="角色名称">
              <el-col :span="12">
                <el-input v-model="form.userName" />
              </el-col>
            </el-form-item>
            <el-form-item label="应用系统">
              <el-col :span="12">
                <el-input v-model="form.system" />
              </el-col>
            </el-form-item>
            <el-form-item label="权限">
              <el-col :span="12">
                <el-cascader
                  v-model="form.auth"
                  :options="options"
                  :props="props"
                  collapse-tags
                  collapse-tags-tooltip
                  clearable
                />
              </el-col>
            </el-form-item>
            <el-table :data="tableData" border style="width: 100%">
              <el-table-column prop="authCode" label="权限代码" />
              <el-table-column prop="authName" label="权限名称" />
              <el-table-column prop="status" label="状态" />
              <el-table-column prop="remark" label="功能描述" />
            </el-table>
          </el-form>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="dialogVisible = false">取消</el-button>
              <el-button type="primary" @click="dialogVisible = false">
                提交
              </el-button>
            </div>
          </template>
        </el-dialog>
      </template>
    </PureTableBar>
  </div>
</template>

<style lang="scss" scoped>
:deep(.el-table__inner-wrapper::before) {
  height: 0;
}

.main-content {
  margin: 24px 24px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>
